package com.zhentao.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zhentao.pojo.R;
import com.zhentao.pojo.VisitGuide;
import com.zhentao.service.VisitGuideService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/visit-guide")
@CrossOrigin(origins = "*", maxAge = 3600)
public class VisitGuideController {

    @Autowired
    private VisitGuideService visitGuideService;

    // 前端首页：按分组返回所有启用项（已按分组、项排序）
    @GetMapping("/all")
    public R<List<VisitGuide>> all() {
        LambdaQueryWrapper<VisitGuide> qw = new LambdaQueryWrapper<>();
        qw.eq(VisitGuide::getStatus, 1)
          .orderByAsc(VisitGuide::getCategoryOrder)
          .orderByAsc(VisitGuide::getItemOrder);
        return R.ok(visitGuideService.list(qw));
    }

    // 按分组获取
    @GetMapping("/by-category")
    public R<List<VisitGuide>> byCategory(@RequestParam String categoryCode) {
        LambdaQueryWrapper<VisitGuide> qw = new LambdaQueryWrapper<>();
        qw.eq(VisitGuide::getStatus, 1)
          .eq(VisitGuide::getCategoryCode, categoryCode)
          .orderByAsc(VisitGuide::getItemOrder);
        return R.ok(visitGuideService.list(qw));
    }

    // 详情（含图文内容）
    @GetMapping("/{id}")
    public R<VisitGuide> detail(@PathVariable Long id) {
        return R.ok(visitGuideService.getById(id));
    }
}


